package com.situ.web.controller;

import com.situ.web.pojo.Banji;
import com.situ.web.service.IBanjiService;
import com.situ.web.service.impl.BanjiServiceImpl;
import com.situ.web.util.JSONResult;
import com.situ.web.util.JSONUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/banji")
public class BanjiServlet extends HttpServlet {
    private IBanjiService banjiService = new BanjiServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        switch (method) {
            case "selectAll":
                selectAll(req, resp);
                break;
        }
    }

    private void selectAll(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        System.out.println("BanjiServlet.selectAll");
        List<Banji> list = banjiService.selectAll();

        JSONUtil.obj2Json(JSONResult.ok(list), resp);
    }
}
